export class appJs {
    constructor(method, id, param) {
        this.method = method;
        this.id = id;
        this.param = param;
        this.setStr();
        this.doAction();
    }
    setStr() {
        let str = '';
        let id = this.id;
        switch(this.method) {
            case 'article.share':/*分享*/
                str = '{"method":"article.share" ,"params":{"articleId":"'+ id +'", "address":"' + this.param  + '"}}';
                break;
            case 'article.test':/* 测评 */
                str = '{"method":"article.test" ,"params":{"articleId":"'+ id +'"}}';
                break;
            case 'article.articleDetail':/* 相关文章 */
                str = '{"method":"article.articleDetail" ,"params":{"articleId":"'+ id +'"}}';
                break;
            case 'article.img':/* 文章图片 */
                str = '{"method":"article.img" ,"params":{"url":"'+ id + '"}}';
                break;
            case 'comment.praiseSave':/* 点赞 */
                str = '{"method":"comment.praiseSave" ,"params":{"commentId":"'+ id + '"}}';
                break;
            case 'comment.praiseDelete':/* 取消赞 */
                str = '{"method":"comment.praiseDelete" ,"params":{"commentId":"'+ id + '"}}';
                break;
            case 'comment.reply':/* 回复 */
                str = '{"method":"comment.reply" ,"params":{"commentId":"'+ id + '"}}';
                break;
            case 'comment.commentList':/* 查看更多评论 */
                str = '{"method":"comment.commentList" ,"params":{"articleId":"'+ id + '"}}';
                break;
        }
        this.str = str;
    }
    doAction() {
        /*console.log(this.str);*/
        if (/android/i.test(navigator.userAgent)){
            //调用安卓
            var action = androidjs.doAction(this.str);
        }
        if (/ipad|iphone|mac/i.test(navigator.userAgent)){
            //调用iOS方法
            window.webkit.messageHandlers.appPostManager.postMessage(this.str);
            /*window.android.startFunction(this.str);*/
        }
    }
}

